package com.jewelry.web.action;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jewelry.common.util.Constants;
import com.jewelry.service.IConfigAttrService;
import com.jewelry.service.ICustomerService;
import com.jewelry.service.IOrdersService;
import com.jewelry.vo.ConfigAttrVO;
import com.jewelry.vo.CustomerVO;
import com.jewelry.vo.OrdersVO;
import com.jewelry.vo.StatisticsVO;

public class OrdersAction extends HttpAction {

	private static final long serialVersionUID = 9199457290590016737L;

	private static Logger logger = LoggerFactory.getLogger(OrdersAction.class);

	private IOrdersService ordersService;

	private List<StatisticsVO> statisticsList;

	private OrdersVO order;

	private List<ConfigAttrVO> materialTypeList;

	private IConfigAttrService configAttrService;

	public IConfigAttrService getConfigAttrService() {
		return configAttrService;
	}

	public void setConfigAttrService(IConfigAttrService configAttrService) {
		this.configAttrService = configAttrService;
	}

	public List<ConfigAttrVO> getMaterialTypeList() {
		return materialTypeList;
	}

	public void setMaterialTypeList(List<ConfigAttrVO> materialTypeList) {
		this.materialTypeList = materialTypeList;
	}

	private List<OrdersVO> ordersList;
	
	private List<CustomerVO> customerList;
	
	private ICustomerService customerService;

	public ICustomerService getCustomerService() {
		return customerService;
	}

	public void setCustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}

	public List<CustomerVO> getCustomerList() {
		return customerList;
	}

	public void setCustomerList(List<CustomerVO> customerList) {
		this.customerList = customerList;
	}

	public List<OrdersVO> getOrdersList() {
		return ordersList;
	}

	public void setOrdersList(List<OrdersVO> ordersList) {
		this.ordersList = ordersList;
	}

	public OrdersVO getOrder() {
		return order;
	}

	public void setOrder(OrdersVO order) {
		this.order = order;
	}

	public List<StatisticsVO> getStatisticsList() {
		return statisticsList;
	}

	public void setStatisticsList(List<StatisticsVO> statisticsList) {
		this.statisticsList = statisticsList;
	}

	public IOrdersService getOrdersService() {
		return ordersService;
	}

	public void setOrdersService(IOrdersService ordersService) {
		this.ordersService = ordersService;
	}

	// ======================================================================

	public String ordersAdminMain() {
		statisticsList = ordersService.getGroupByOrderState();
		return SUCCESS;
	}

	public String queryOrdersList() {
		if (logger.isDebugEnabled()) {
			logger.debug("Start queryOrdersList ... ");
		}
		if (order == null) {
			order = new OrdersVO();
		}
		try {
			ordersList = ordersService.getOrdersListByPage(order);
		} catch (Exception e) {
			logger.error("getOrdersListByPage error!", e);
		}
		return SUCCESS;
	}

	public String addOrdersPage() {
		if (order == null) {
			order = new OrdersVO();
		}
		CustomerVO customer = new CustomerVO();
		try {
			order.setOrderid(ordersService.getOrderID());
			order.setOrderTime(new Date());
			materialTypeList = configAttrService
					.getConfigAttrListByConfigGroup(Constants.MATERIAL_TYPE_COONFIG);
			customerList = customerService.getCustomerList(customer);
		} catch (Exception e) {
			logger.error("getConfigAttrListByConfigGroup error!", e);
		}
		return SUCCESS;
	}

	public String addingOrders() {
		return SUCCESS;
	}

}
